package org.judking.CarKeeper.command.EarlyWarning;

import org.judking.CarKeeper.command.BaseObdCommand;

public class SpeedDetector implements WarningDetector	 {
	private final int SPEED_UP_BOUNDARY = 50;
	private final int LOW_SPEED_BOUNADARY = 10;
	private final int TIME_TICK_LIMIT = 4;
	private boolean iSpeedUp = false;
	private Counter counter;
	
	
	public SpeedDetector()			{
		counter = new Counter(TIME_TICK_LIMIT);
	}

	@Override
	public void detect(BaseObdCommand command) {
		int curSpeed = Integer.parseInt(command.getRipeData().toString());
		
		if(iSpeedUp == false)		{
			iSpeedUp = (curSpeed >= SPEED_UP_BOUNDARY) ? true : false;
		}
		else		{
			if(curSpeed <= LOW_SPEED_BOUNADARY)		{
				if(counter.tick() == true)		{
//					alert();
				}
			}
			if(curSpeed > LOW_SPEED_BOUNADARY && curSpeed < SPEED_UP_BOUNDARY)		{
				iSpeedUp = false;
				counter.reset();
			}
		}
	}

}
